package project2011;
import java.util.*;

/**
 * A ProductList stores products in an ArrayList called queue
 * @author Antone Gonzalez
 */
public class ProductList{
    /**
     * The constructor for ProductList assigns a new ArrayList to queue
     */
    public ProductList()
    {
        queue = new ArrayList<Product>();
    }
    /**
     * Adds a passed in product to the queue
     * @param toAdd The product to be added to the queue
     */
    public void addProduct(Product toAdd)
    {
        queue.add(toAdd);
        totalPrice += toAdd.getPrice();
    }
    public void changePrice(Product toChange,double newPrice){
        toChange.changePrice(newPrice);
    }
    
    /**
     * removes a product with passed in UPC from queue
     * @param UPC the upc number of the product to remove
     */
    public void removeProduct(int UPC)
    {
        for(Product x: queue)
        {
            if(x.getUPC() == UPC)
            {
                queue.remove(x);
            }
        }
    }
    
    /**
     * Finds a product in the queue searching by UPC number
     * @param UPC The UPC number that will be searched for in the queue
     * @return If the UPC number is found in the queue, the associated Product will
     * be returned. If the UPC is not found, this method returns null.
     */
    public Product find(int UPC)
    {        
        for(Product x : queue)
        {
            if(x.getUPC() == UPC)
            {
                return x;
            }
        }
        return null;
    }
    /**
     * returns a string with all product details printed in order
     * @return the string with all product details
     */
    public String print()
    {
        String result = new String();
        for(Product x: queue)
        {
            result += x.print();
        }
        return result;
    }
    
    /**
     * accessor for amount of items in this productlist
     * @return int of amount of products in this list
     */
    public int getSize()
    {
        return queue.size();
    }
        
    ArrayList<Product> queue;
    double totalPrice;
}
